﻿using SYJ.BLL;
using SYJ.Common.web;
using SYJ.IBLL;
using SYJ.Model;
using SYJ.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Dapper;
using System.Collections;
using System.IO;
using System.Web;
using System.Globalization;

namespace SYJ.Logic.Controllers.admin
{
   public class ContestMgrController:BaseController
    {
       IContestBLL bll = new ContestBLL();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetContestList(QueryModel query, string title, int? status)
        {
            long count = 0;
            if (!string.IsNullOrEmpty(title))
            {
                query.SqlWhere = " and title like ?title ";
                query.Param.Add("title", "%" + title + "%");
            }
            if (status != null && status > 0)
            {
                query.SqlWhere += " and status = ?status ";
                query.Param.Add("status", status);
            }
            List<Contest> list = bll.GetPage(query, out count);
            var respose = JsonLayuiGridData<Contest>.Create(query, list, count, "");
            return Json(respose, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        [ValidateInput(false)]
        public ActionResult AddOrUp(int? id)
        {
            Contest role = new Contest();
            if (id != null)
            {
                role = bll.GetModel(Convert.ToInt32(id));
            }
            return View(role);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult AddOrUp(Contest model)
        {
            model.user_id = AppContext.Current.User.id;
            if (model.id > 0)
            {
                return Json(bll.Update(model), JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(bll.Insert(model), JsonRequestBehavior.AllowGet);
            }
        }

        public ActionResult Delete(int id)
        {
            bool delete = bll.Delete(new Contest() { id = id });
            return Json(delete, JsonRequestBehavior.AllowGet);
        }
    }
}
